<?php

/*
	* OpenGSP (c) 2011
	* Author(s): Christopher Martino
	* Module: mysqli.base.php
	* Updated: 29/03/2011
	* http://opengsp.com/
*/

class MySQLi_BASE
{
    private static $mysqli_handle;
	
    private static $query_total;
	

    function __construct ( $hostname, $username, $password, $database )
    {
        self::$query_total   = 0;
        self::$mysqli_handle = new mysqli($hostname, $username, $password, $database);
                
        if ( is_object ( $this->mysqli_handle ) === false )
        {
            self::$mysqli_handle = NULL;
			
            die("OpenGSP: Something didn't quite go to plan there! Please try again later.");
        }
    }
	
		
	/*
		===
		= Data Management
		===
	*/
	
    public static function escape_input($user_input)
    {
        return self::$mysqli_handle->real_escape_string($user_input);
    }
	
	
	/*
		===
		= Database Management
		===
	*/
	
    public static function query_database($query_string)
    {
        self::$query_total++;
		
        return self::$mysqli_handle->query($query_string);
    }
	
    public static function total_rows($query_string)
    {
        self::query_database($query_string);
       
		return self::$mysqli_handle->affected_rows;
    }
	
    public static function data_array($query_string)
    {
        $data_array = self::query_database($query_string);
        
		return $data_array->fetch_assoc( );
    }
}